// 注册
$(function () {
  $('#registerForm').bootstrapValidator({
      //提供输入验证图标提示
      feedbackIcons: {
          valid: 'glyphicon glyphicon-ok',
          invalid: 'glyphicon glyphicon-remove',
          validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        tel: {
            validators: {
                notEmpty: {
                    message: '请输入手机号'
                },
                regexp: {
                  regexp: /^1[3456789]\d{9}$/,
                  message: '手机号不合法'
                }
            }
        },
        verificationCode: {
          validators: {
            notEmpty: {
                message: '请输入短信验证码'
            }
          }
        },
        password: {
            validators: {
              notEmpty: {
                  message: '密码不能为空'
              },
              stringLength: {
                  min: 6,
                  max: 16,
                  message: '密码长度必须在6到16位之间'
              }
            }
        },
        agree: {
          validators: {
            notEmpty: {
                message: ' '
            }
          }
        }
      }
  })
  .on('success.form.bv', function(e) {//点击提交之后
     e.preventDefault();
     var $form = $(e.target);
     var bv = $form.data('bootstrapValidator');
     location.href = "perfectInfor.html"
     // Use Ajax to submit form data 提交至form标签中的action，result自定义
     $.post($form.attr('action'), $form.serialize(), function(result) {
        //恢复submit按钮disable状态。
         $('#registerForm').bootstrapValidator('disableSubmitButtons', false);
        //  跳转完善个人资料页
        location.href = "perfectInfor.html"
     });
  });
});

// 完善资料perfectForm
$(function () {
  $('#perfectForm').bootstrapValidator({
      //提供输入验证图标提示
      feedbackIcons: {
          valid: 'glyphicon glyphicon-ok',
          invalid: 'glyphicon glyphicon-remove',
          validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        username: {
            validators: {
                notEmpty: {
                    message: '请输入姓名'
                },
                stringLength: {
                  max: 10,
                  message: '用户名长度不能超过10位'
                }
            }
        },
        identity: {
          validators: {
            notEmpty: {
                message: '请输入短信身份证号'
            },
            regexp: {
              regexp: /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
              message: '身份证号码不合法'
            }
          }
        },
        email: {
            validators: {
                notEmpty: {
                    message: '邮箱不能为空'
                },
                regexp: {
                    regexp: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
                    message: '邮箱不合法'
                }
            }
        }
      }
  })
  .on('success.form.bv', function(e) {//点击提交之后
     e.preventDefault();
     var $form = $(e.target);
     var bv = $form.data('bootstrapValidator');
     location.href = "index.html";
     // Use Ajax to submit form data 提交至form标签中的action，result自定义
     $.post($form.attr('action'), $form.serialize(), function(result) {
        //恢复submit按钮disable状态。
         $('#perfectForm').bootstrapValidator('disableSubmitButtons', false);
         location.href = "index.html"
     });
  });
});

// 忘记密码forgotForm
$(function () {
  $('#forgotForm').bootstrapValidator({
    //提供输入验证图标提示
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
      tel: {
        validators: {
          notEmpty: {
            message: '请输入手机号'
          },
          regexp: {
            regexp: /^1[3456789]\d{9}$/,
            message: '手机号不合法'
          }
        }
      },
      verificationCode: {
        validators: {
          notEmpty: {
            message: '请输入短信验证码'
          }
        }
      },
      password: {
        validators: {
          notEmpty: {
            message: '密码不能为空'
          },
          stringLength: {
            min: 6,
            max: 16,
            message: '密码长度必须在6到16位之间'
          },
          identical:{
            field: 'confirmPassword',
            message: '两次密码不一致'
          }
        }
      },
      confirmPassword: {
        validators: {
          notEmpty: {
            message: '密码不能为空'
          },
          stringLength: {
            min: 6,
            max: 16,
            message: '密码长度必须在6到16位之间'
          },
          identical:{
            field: 'password',
            message: '两次密码不一致'
          }
        }
      }
    }
  })
  .on('success.form.bv', function(e) {//点击提交之后
     e.preventDefault();
     var $form = $(e.target);
     var bv = $form.data('bootstrapValidator');
     location.href = "index.html"
     // Use Ajax to submit form data 提交至form标签中的action，result自定义
     $.post($form.attr('action'), $form.serialize(), function(result) {
        //恢复submit按钮disable状态。
         $('#forgotForm').bootstrapValidator('disableSubmitButtons', false);
         location.href = "index.html"
     });
  });
});

// 登录tab
$('#pills-tab a').on('click', function (e) {
  e.preventDefault()
  $(this).tab('show')
})

// 账号密码登录
$(function () {
  $('#loginForm').bootstrapValidator({
      //提供输入验证图标提示
      feedbackIcons: {
          valid: 'glyphicon glyphicon-ok',
          invalid: 'glyphicon glyphicon-remove',
          validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        tel: {
            validators: {
                notEmpty: {
                    message: '请输入手机号'
                },
                /* regexp: {
                  regexp: /^1[3456789]\d{9}$/,
                  message: '手机号不合法'
                } */
            }
        },
        password: {
            validators: {
              notEmpty: {
                  message: '密码不能为空'
              },
              /* stringLength: {
                  min: 6,
                  max: 16,
                  message: '密码长度必须在6到16位之间'
              } */
            }
        }
      }
  })
  .on('success.form.bv', function(e) {//点击提交之后
     e.preventDefault();
     var $form = $(e.target);
     var bv = $form.data('bootstrapValidator');
     location.href = "index.html"
     // Use Ajax to submit form data 提交至form标签中的action，result自定义
     $.post($form.attr('action'), $form.serialize(), function(result) {
        //恢复submit按钮disable状态。
         $('#loginForm').bootstrapValidator('disableSubmitButtons', false);
         location.href = "index.html"
     });
  });
});

// 短信验证码登录
$(function () {
  $('#phoneForm').bootstrapValidator({
      //提供输入验证图标提示
      feedbackIcons: {
          valid: 'glyphicon glyphicon-ok',
          invalid: 'glyphicon glyphicon-remove',
          validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        tel: {
            validators: {
                notEmpty: {
                    message: '请输入手机号'
                }
            }
        },
        verificationCode: {
          validators: {
            notEmpty: {
                message: '请输入短信验证码'
            }
          }
        }
      }
  })
  .on('success.form.bv', function(e) {//点击提交之后
     e.preventDefault();
     var $form = $(e.target);
     var bv = $form.data('bootstrapValidator');
     location.href = "index.html"
     // Use Ajax to submit form data 提交至form标签中的action，result自定义
     $.post($form.attr('action'), $form.serialize(), function(result) {
        //恢复submit按钮disable状态。
         $('#phoneForm').bootstrapValidator('disableSubmitButtons', false);
         location.href = "index.html"
     });
  });
});

$(function(){
  $('#button-addon2').on('click', function(){
    var _this = this;
    var time = 30;
    $(this).text(time+"s后重发")
    $(this).attr("disabled", true);
    function countDown(){
      time--;
      $(_this).text(time+"s后重发")
      if(time <= 0){
        clearInterval(inter)
        $(_this).attr("disabled", false);
        $(_this).text("获取验证码")
      } 
    }
    var inter = setInterval(function(){countDown()}, 1000)
  })
})